//
//  PersonViewController.m
//  bluetooth
//
//  Created by 周季阳 on 15/7/15.
//  Copyright (c) 2015年 switch. All rights reserved.
//

#import "PersonViewController.h"
#import "LoginViewController.h"
#import "AppDelegate.h"
#import "UIViewAdditions.h"
#import "EditPersonViewController.h"
@interface PersonViewController ()
{
    UIView *backView;
}
@end

@implementation PersonViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initNav];
    self.view.backgroundColor = [self colorWithHexString:@"#F5F5F5"];

    navTitle.text = @"个人中心";
    [navRightBtn setTitle:@"更换账号" forState:UIControlStateNormal];
    navRightBtn.frame = CGRectMake(SCREEN_WIDTH-74 , 20, 64, SCREEN_WIDTH*0.2-20);
    navRightBtn.hidden = NO;
    
    [navBtn setImage:[UIImage imageNamed:@"制作完成_03"] forState:UIControlStateNormal];
    navBtn.frame = CGRectMake(10, 30, 63, 21);
    
    [self initUI];
}
#pragma mark - initUI
-(void)initUI{
    backView = [[UIView alloc]initWithFrame:CGRectMake(0, navView.bottom, SCREEN_WIDTH, 120)];
    backView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:backView];
    
    UILabel *label1 = [self createLabel:@"姓名:" andFrame:CGRectMake(10, 0, 42, 30)];
    [self createLine:CGRectMake(10, 30, SCREEN_WIDTH-20, 0.5)];
    UILabel *label2 = [self createLabel:@"电话:" andFrame:CGRectMake(10, label1.bottom, 42, 30)];
    [self createLine:CGRectMake(10, 60, SCREEN_WIDTH-20, 0.5)];
    UILabel *label3 = [self createLabel:@"地址:" andFrame:CGRectMake(10, label2.bottom, 42, 30)];
    
    UILabel *value1 = [self createValue:@"谷铮" andFrame:CGRectMake(label1.right, 0, SCREEN_WIDTH-10-label1.right, 30)];
    UILabel *value2 = [self createValue:@"15232365651(您的账号)" andFrame:CGRectMake(label2.right, value1.bottom, SCREEN_WIDTH-10-label2.right, 30)];
    
    UILabel *value3 = [[UILabel alloc] initWithFrame:CGRectMake(label3.right, label2.bottom, SCREEN_WIDTH-10-label3.right, 50)];
    value3.text = @"北京市朝阳区北苑路40号有色金属与稀有应用研究所内彩钢2号楼C-UK";
    value3.textColor = [UIColor blackColor];
    value3.numberOfLines = 0;
    value3.font = [UIFont systemFontOfSize:14];
    value3.textAlignment= NSTextAlignmentLeft;
    [backView addSubview:value3];
   
    UIButton *editBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    editBtn .frame = CGRectMake((SCREEN_WIDTH-286)/2, backView.bottom+50, 286, 37);
    [editBtn setBackgroundImage:[UIImage imageNamed:@"个人中心_03"] forState:UIControlStateNormal];
    [editBtn addTarget:self action:@selector(clickEditBtn) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:editBtn];
    
}
#pragma mark - 点击编辑
-(void)clickEditBtn{
    EditPersonViewController *edit = [[EditPersonViewController alloc]init];
    [self.navigationController pushViewController:edit animated:YES];
}
#pragma mark - 线
-(void)createLine:(CGRect)frame{
    UIView *line = [[UIView alloc]initWithFrame:frame];
    line.backgroundColor = [UIColor grayColor];
    [backView addSubview:line];
}
#pragma mark - 更换账号
-(void)clickRightBtn{
    AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    // 在delegate中初始化新的controller
    //[delegate initTabbarController];
    // 修改rootViewController
    LoginViewController *mainVC = [LoginViewController new];
    UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:mainVC];
    
    [delegate.window addSubview:nav1.view];
    [self.view removeFromSuperview];
    delegate.window.rootViewController = nav1;

}
#pragma mark - 返回菜单
-(void)clickBackBtn{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - 创建label
-(UILabel *)createLabel:(NSString *)title andFrame:(CGRect)frame{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.text = title;
    label.textColor = [UIColor lightGrayColor];
    label.font = [UIFont systemFontOfSize:14];
    label.textAlignment= NSTextAlignmentLeft;
    [backView addSubview:label];
    return label ;
}
#pragma mark - 创建value
-(UILabel *)createValue:(NSString *)title andFrame:(CGRect)frame{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.text = title;
    label.textColor = [UIColor blackColor];
    label.font = [UIFont systemFontOfSize:14];
    label.textAlignment= NSTextAlignmentLeft;
    [backView addSubview:label];
    return label ;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
